package mock;

import org.junit.jupiter.api.Test;

import java.util.LinkedList;
import java.util.List;

import static org.mockito.Mockito.*;

class Mock {

    @Test
    void testMock() {
        List list = mock(List.class);
        list.add("one");
        //list.clear();
        verify(list).add("one");
        verify(list).clear();
    }

    @Test
    void testStub() {
        LinkedList list = mock(LinkedList.class);
        when(list.get(0)).thenReturn("first");
        when(list.get(1)).thenThrow(new RuntimeException());

        System.out.println(list.get(0));
        //System.out.println(list.get(1));
        //System.out.println(list.get(999));

        verify(list).get(0);
    }

    @Test
    void testParameter() {
        LinkedList list = mock(LinkedList.class);
        when(list.get(anyInt())).thenReturn("element");

        System.out.println(list.get(999));
        verify(list).get(anyInt());

        list.add("first");


        verify(list, times(1)).get(anyInt());
        verify(list, never()).add("never happened");
        verify(list, atLeastOnce()).add("first");
        verify(list, atLeast(1)).add("first");
        verify(list, atMost(5)).add("first");
    }

    @Test
    void testStubException() {

    }
}
